local gamelib = require "club.threecard.gamelib"
local game = require "club.threecard.bjracing"
local LoopScrollList = require "blaze.ui.widget.LoopScrollList"
local rank_item = game.require "gameui.gamescene.rank_item"

local rank_list = gamelib.ui.element()

rank_list.store_watchers = 
{
    ingame = 
    {
        ["on_statistics"] = function(self, store, state, args, isInitialize)
            self:update(state.statistics);
        end
    }
}

function rank_list:ctor()
    self.res = "club.threecard.bjracing/ui/gamescene.b:rank_list"
    self.app = game;
    self.list = LoopScrollList.new();
    self.list.res = "club.threecard.bjracing/ui/gamescene.b:rank_item";
    self.list.create_item = function(_, data, index) return rank_item.new(data) end;
end

function rank_list:on_load()
    self.list:load();
    self:super("on_load");
end

function rank_list:on_injected()
    self.list:attach(self.scroll_view);
end

function rank_list:update(statistics)
    local total_player_count = statistics.total_player_count;
    local seen_player_count = statistics.seen_player_count;
    local exchange_player_count = statistics.exchange_player_count;

    self.total_txt.text = string.format("总共:%s人  看牌:%s人  换牌:%s人", total_player_count, seen_player_count, exchange_player_count);
    self.list:fill(statistics.top_bets);
end

return rank_list